package com.wb3.meta.api.core.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wb3.meta.api.core.dao.WinningRecordMapper;
import com.wb3.meta.api.core.model.WinningRecord;
import com.wb3.meta.api.core.service.WinningRecordService;
import com.wb3.meta.api.core.vo.ReqWinningRecordVo;
import com.wb3.meta.api.core.vo.ResWinningRecordVo;
import com.wb3.meta.common.authentication.RequestHolder;
import com.wb3.meta.common.enums.EnumConstants;
import com.wb3.meta.common.mybatis.DataTableUtil;
import com.wb3.meta.common.pojo.ResultT;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Slf4j
@Service("winningRecordService")
@Transactional(transactionManager = "dataSourceTransactionManagerOne", rollbackFor = Exception.class)
public class WinningRecordServiceImpl implements WinningRecordService {
    @Autowired
    private WinningRecordMapper winningRecordMapper;
    /**
     * 分页查询方法
     *
     * @param vo
     * @return
     */
    @Override
    public Page<ResWinningRecordVo> getModelPage(ReqWinningRecordVo vo) {

        PageHelper.startPage(vo.getPageNum(), vo.getPageSize());

        return (Page<ResWinningRecordVo>) getModelListByConditions(vo);
    }

    /**
     * 列表查询方法 -返回 res 对象
     *
     * @param vo
     * @return
     */
    @Override
    public List<ResWinningRecordVo> getModelListByConditions(ReqWinningRecordVo vo) {
        vo.setUserId(RequestHolder.getUserId());
        return winningRecordMapper.getModelListByConditions(vo);
    }

    /**
     * 根据条件查询单条数据方法，返回res vo类
     *
     * @param vo
     * @return
     */
    @Override
    public ResWinningRecordVo getResModelByConditions(ReqWinningRecordVo vo) {
        return winningRecordMapper.getResModelByConditions(vo);
    }

    /**
     * 根据条件查询单个对象方法
     *
     * @param winningRecord
     * @return
     */
    @Override
    public WinningRecord getModelByConditions(WinningRecord winningRecord) {
        return null;
    }

    /**
     * 根据id查询单个对象方法
     *
     * @param id
     * @return
     */
    @Override
    public WinningRecord getModelById(Object id) {
        return winningRecordMapper.selectByPrimaryKey(id);
    }

    /**
     * 新增对象方法
     *
     * @param winningRecord
     */
    @Override
    public void addModel(WinningRecord winningRecord) {
        winningRecord.setCreateTime(new Date().getTime());
        winningRecord.setStatus(EnumConstants.StatusEnum.VALID.getCode());
        winningRecordMapper.insertUseGeneratedKeys(winningRecord);
    }

    /**
     * 更新对象方法
     *
     * @param winningRecord
     */
    @Override
    public void updateModel(WinningRecord winningRecord) {
        winningRecord.setUpdateTime(new Date().getTime());
        winningRecordMapper.updateByPrimaryKeySelective(winningRecord);
    }

    /**
     * 根据id删除对象方法
     *
     * @param id
     */
    @Override
    public void deleteModelById(Object id) {

    }

    /**
     * 获取分页数据，返回 map对象方法
     *
     * @param vo
     * @return
     */
    @Override
    public ResultT getModelMapPage(ReqWinningRecordVo vo) {
        return ResultT.success(DataTableUtil.changePage(getModelPage(vo)));
    }

    /**
     * 根据id查询单个对象方法，返回 map对象方法
     *
     * @param id
     * @return
     */
    @Override
    public ResultT getModelMapById(Object id) {
        return null;
    }

    /**
     * 根据条件查询单个对象，返回map对象方法
     *
     * @param winningRecord
     * @return
     */
    @Override
    public ResultT getModelMapByConditions(WinningRecord winningRecord) {
        return null;
    }

    /**
     * 查询列表-map对象
     *
     * @param vo
     * @return
     */
    @Override
    public ResultT getResModelListMapByConditions(ReqWinningRecordVo vo) {
        return ResultT.success(winningRecordMapper.getModelListByConditions(vo));
    }

    /**
     * 根据条件查询res vo对象，返回map对象方法
     *
     * @param vo
     * @return
     */
    @Override
    public ResultT getResModelMapByConditions(ReqWinningRecordVo vo) {
        return null;
    }

    /**
     * 更新或插入对象方法
     *
     * @param vo
     * @return
     */
    @Override
    public ResultT saveOrUpdate(ReqWinningRecordVo vo) {
        if (vo.getId() != null) {
            updateModel(vo);
        } else {
            addModel(vo);
        }
        return ResultT.success(vo);
    }

    /**
     * 根据条件删除方法
     *
     * @param vo
     * @return
     */
    @Override
    public ResultT delete(ReqWinningRecordVo vo) {
        return null;
    }


}
